package NC;

import java.util.Arrays;

public class NC17 {
    public int getLongestPalindrome(String A, int n) {
        // write code here
        if (n == 0) return 0;
        boolean[][] dp = new boolean[n][n];
        int ans = 1;
        for (int d = 0; d < n; d++) {
            for (int i = 0; i < n - d; i++) {
                int j = i + d;
                if (A.charAt(i) == A.charAt(j)) {
                    if (d == 0 || d == 1) {
                        dp[i][j] = true;
                    } else {
                        dp[i][j] = dp[i + 1][j - 1];
                    }
                    if (dp[i][j]) {
                        ans = Math.max(ans, d+1);
                    }
                }
            }
        }
        return ans;
    }
}
